using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Collections;
using System.Windows.Forms;
using System.Configuration;
using WorkThreading;
using SMS.SmManager;
using SMS.ProcessUtils;

namespace SMS.ProcessMsgIn
{
    public partial class ThreadFormIn : Form
    {
        private Int32[] total81XX;
        private Int32[] total82XX;
        private Int32[] total83XX;
        private Int32[] total84XX;
        private Int32[] total85XX;
        private Int32[] total86XX;
        private Int32[] total87XX;
        private Int32[] total80XX;
        private Int32[] totalPartner;

        private WorkQueue work81;
        private WorkQueue work82;
        private WorkQueue work83;
        private WorkQueue work84;
        private WorkQueue work85;
        private WorkQueue work86;
        private WorkQueue work87;
        private WorkQueue work80;
        private WorkQueue workPartner;

        private TimeSpan refreshInterval;
        private DateTime nextRefreshTime;

        public ThreadFormIn()
        {
            InitializeComponent();

            nextRefreshTime = DateTime.Now;
            refreshInterval = TimeSpan.FromSeconds(0.20);

            #region Config Initial
            // Config SMS 80
            total80XX = new int[6];
            work80 = new WorkQueue();
            work80.ConcurrentLimit = 500;
            work80.AllWorkCompleted += new EventHandler(work80_AllWorkCompleted);
            work80.WorkerException += new ResourceExceptionEventHandler(work80_WorkerException);
            work80.ChangedWorkItemState += new ChangedWorkItemStateEventHandler(work80_ChangedWorkItemState);
            work80.FailedWorkItem += new WorkItemEventHandler(work80_FailedWorkItem);

            txtMinthread80XX.Text = ((WorkThreadPool)work80.WorkerPool).MinThreads.ToString();
            txtMaxthread80XX.Text = ((WorkThreadPool)work80.WorkerPool).MaxThreads.ToString();
            txtConcurrent80XX.Text = work80.ConcurrentLimit.ToString();

            // Config 81
            total81XX = new int[6];
            work81 = new WorkQueue();
            work81.ConcurrentLimit = 500;
            work81.AllWorkCompleted += new EventHandler(work81_AllWorkCompleted);
            work81.WorkerException += new ResourceExceptionEventHandler(work81_WorkerException);
            work81.ChangedWorkItemState += new ChangedWorkItemStateEventHandler(work81_ChangedWorkItemState);
            work81.FailedWorkItem += new WorkItemEventHandler(work81_FailedWorkItem);

            txtMinthread81XX.Text = ((WorkThreadPool)work81.WorkerPool).MinThreads.ToString();
            txtMaxthread81XX.Text = ((WorkThreadPool)work81.WorkerPool).MaxThreads.ToString();
            txtConcurrent81XX.Text = work81.ConcurrentLimit.ToString();

            // Config 82
            total82XX = new int[6];
            work82 = new WorkQueue();
            work82.ConcurrentLimit = 500;
            work82.AllWorkCompleted += new EventHandler(work82_AllWorkCompleted);
            work82.WorkerException += new ResourceExceptionEventHandler(work82_WorkerException);
            work82.ChangedWorkItemState += new ChangedWorkItemStateEventHandler(work82_ChangedWorkItemState);
            work82.FailedWorkItem += new WorkItemEventHandler(work82_FailedWorkItem);

            txtMinthread82XX.Text = ((WorkThreadPool)work82.WorkerPool).MinThreads.ToString();
            txtMaxthread82XX.Text = ((WorkThreadPool)work82.WorkerPool).MaxThreads.ToString();
            txtConcurrent82XX.Text = work82.ConcurrentLimit.ToString();

            // Config 83
            total83XX = new int[6];
            work83 = new WorkQueue();
            work83.ConcurrentLimit = 500;
            work83.AllWorkCompleted += new EventHandler(work83_AllWorkCompleted);
            work83.WorkerException += new ResourceExceptionEventHandler(work83_WorkerException);
            work83.ChangedWorkItemState += new ChangedWorkItemStateEventHandler(work83_ChangedWorkItemState);
            work83.FailedWorkItem += new WorkItemEventHandler(work83_FailedWorkItem);

            txtMinthread83XX.Text = ((WorkThreadPool)work83.WorkerPool).MinThreads.ToString();
            txtMaxthread83XX.Text = ((WorkThreadPool)work83.WorkerPool).MaxThreads.ToString();
            txtConcurrent83XX.Text = work83.ConcurrentLimit.ToString();

            // Config 84
            total84XX = new int[6];
            work84 = new WorkQueue();
            work84.ConcurrentLimit = 500;
            work84.AllWorkCompleted += new EventHandler(work84_AllWorkCompleted);
            work84.WorkerException += new ResourceExceptionEventHandler(work84_WorkerException);
            work84.ChangedWorkItemState += new ChangedWorkItemStateEventHandler(work84_ChangedWorkItemState);
            work84.FailedWorkItem += new WorkItemEventHandler(work84_FailedWorkItem);

            txtMinthread84XX.Text = ((WorkThreadPool)work84.WorkerPool).MinThreads.ToString();
            txtMaxthread84XX.Text = ((WorkThreadPool)work84.WorkerPool).MaxThreads.ToString();
            txtConcurrent84XX.Text = work84.ConcurrentLimit.ToString();

            // Config 85
            total85XX = new int[6];
            work85 = new WorkQueue();
            work85.ConcurrentLimit = 500;
            work85.AllWorkCompleted += new EventHandler(work85_AllWorkCompleted);
            work85.WorkerException += new ResourceExceptionEventHandler(work85_WorkerException);
            work85.ChangedWorkItemState += new ChangedWorkItemStateEventHandler(work85_ChangedWorkItemState);
            work85.FailedWorkItem += new WorkItemEventHandler(work85_FailedWorkItem);

            txtMinthread85XX.Text = ((WorkThreadPool)work85.WorkerPool).MinThreads.ToString();
            txtMaxthread85XX.Text = ((WorkThreadPool)work85.WorkerPool).MaxThreads.ToString();
            txtConcurrent85XX.Text = work85.ConcurrentLimit.ToString();

            // Config 86
            total86XX = new int[6];
            work86 = new WorkQueue();
            work86.ConcurrentLimit = 500;
            work86.AllWorkCompleted += new EventHandler(work86_AllWorkCompleted);
            work86.WorkerException += new ResourceExceptionEventHandler(work86_WorkerException);
            work86.ChangedWorkItemState += new ChangedWorkItemStateEventHandler(work86_ChangedWorkItemState);
            work86.FailedWorkItem += new WorkItemEventHandler(work86_FailedWorkItem);

            txtMinthread86XX.Text = ((WorkThreadPool)work86.WorkerPool).MinThreads.ToString();
            txtMaxthread86XX.Text = ((WorkThreadPool)work86.WorkerPool).MaxThreads.ToString();
            txtConcurrent86XX.Text = work86.ConcurrentLimit.ToString();

            // Config 87
            total87XX = new int[6];
            work87 = new WorkQueue();
            work87.ConcurrentLimit = 500;
            work87.AllWorkCompleted += new EventHandler(work87_AllWorkCompleted);
            work87.WorkerException += new ResourceExceptionEventHandler(work87_WorkerException);
            work87.ChangedWorkItemState += new ChangedWorkItemStateEventHandler(work87_ChangedWorkItemState);
            work87.FailedWorkItem += new WorkItemEventHandler(work87_FailedWorkItem);

            txtMinthread87XX.Text = ((WorkThreadPool)work87.WorkerPool).MinThreads.ToString();
            txtMaxthread87XX.Text = ((WorkThreadPool)work87.WorkerPool).MaxThreads.ToString();
            txtConcurrent87XX.Text = work87.ConcurrentLimit.ToString();

            // Config Partner
            totalPartner = new int[6];
            workPartner = new WorkQueue();
            workPartner.ConcurrentLimit = 500;
            workPartner.AllWorkCompleted += new EventHandler(workPartner_AllWorkCompleted);
            workPartner.WorkerException += new ResourceExceptionEventHandler(workPartner_WorkerException);
            workPartner.ChangedWorkItemState += new ChangedWorkItemStateEventHandler(workPartner_ChangedWorkItemState);
            workPartner.FailedWorkItem += new WorkItemEventHandler(workPartner_FailedWorkItem);

            txtMinthreadPartner.Text = ((WorkThreadPool)workPartner.WorkerPool).MinThreads.ToString();
            txtMaxthreadPartner.Text = ((WorkThreadPool)workPartner.WorkerPool).MaxThreads.ToString();
            txtConcurrentPartner.Text = workPartner.ConcurrentLimit.ToString();

            #endregion Config Initial
        }

        private void ThreadFormIn_Load(object sender, EventArgs e)
        {
            this.txtTotalSms80XX.Text = "0";
            this.txtTotalSms81XX.Text = "0";
            this.txtTotalSms82XX.Text = "0";
            this.txtTotalSms83XX.Text = "0";
            this.txtTotalSms84XX.Text = "0";
            this.txtTotalSms85XX.Text = "0";
            this.txtTotalSms86XX.Text = "0";
            this.txtTotalSms87XX.Text = "0";            
            this.txtTotalSmsPartner.Text = "0";
            this.Text = ConfigurationManager.AppSettings["Version"].ToString() + " - " + this.Text + " - " + ConfigurationManager.AppSettings["ServiceID"].ToString();
        }

        #region Button Events

        private void btnExit_Click(object sender, EventArgs e)
        {
            base.Close();
        }

        private void btnStart81XX_Click(object sender, EventArgs e)
        {
            if (this.btnStart81XX.Text.ToLower() == "start")
            {
                this.time81XX.Enabled = true;
                btnStart81XX.Text = "Stopped";
                lblStatus81XX.Text = "Running";
            }
            else
            {
                this.btnStart81XX.Text = "Start";
                this.time81XX.Enabled = false;
                this.lblStatus81XX.Text = "Stopped";
                this.Cursor = Cursors.Arrow;
            }
        }

        private void btnStart82XX_Click(object sender, EventArgs e)
        {
            if (this.btnStart82XX.Text.ToLower() == "start")
            {
                this.time82XX.Enabled = true;
                this.btnStart82XX.Text = "Stopped";
                this.lblStatus82XX.Text = "Running";
            }
            else
            {
                this.btnStart82XX.Text = "Start";
                this.time82XX.Enabled = false;
                this.lblStatus82XX.Text = "Stopped";
                this.Cursor = Cursors.Arrow;
            }
        }

        private void btnStart83XX_Click(object sender, EventArgs e)
        {
            if (this.btnStart83XX.Text.ToLower() == "start")
            {
                this.time83XX.Enabled = true;
                this.btnStart83XX.Text = "Stopped";
                this.lblStatus83XX.Text = "Running";
            }
            else
            {
                this.btnStart83XX.Text = "Start";
                this.time83XX.Enabled = false;
                this.lblStatus83XX.Text = "Stopped";
                this.Cursor = Cursors.Arrow;
            }
        }

        private void btnStart84XX_Click(object sender, EventArgs e)
        {
            if (this.btnStart84XX.Text.ToLower() == "start")
            {
                this.time84XX.Enabled = true;
                this.btnStart84XX.Text = "Stopped";
                this.lblStatus84XX.Text = "Running";
            }
            else
            {
                this.btnStart84XX.Text = "Start";
                this.time84XX.Enabled = false;
                this.lblStatus84XX.Text = "Stopped";
                this.Cursor = Cursors.Arrow;
            }
        }

        private void btnStart85XX_Click(object sender, EventArgs e)
        {
            if (this.btnStart85XX.Text.ToLower() == "start")
            {
                this.time85XX.Enabled = true;
                this.btnStart85XX.Text = "Stopped";
                this.lblStatus85XX.Text = "Running";
            }
            else
            {
                this.btnStart85XX.Text = "Start";
                this.time85XX.Enabled = false;
                this.lblStatus85XX.Text = "Stopped";
                this.Cursor = Cursors.Arrow;
            }
        }

        private void btnStart86XX_Click(object sender, EventArgs e)
        {
            if (this.btnStart86XX.Text.ToLower() == "start")
            {
                this.time86XX.Enabled = true;
                this.btnStart86XX.Text = "Stopped";
                this.lblStatus86XX.Text = "Running";
            }
            else
            {
                this.btnStart86XX.Text = "Start";
                this.time86XX.Enabled = false;
                this.lblStatus86XX.Text = "Stopped";
                this.Cursor = Cursors.Arrow;
            }
        }

        private void btnStart87XX_Click(object sender, EventArgs e)
        {
            if (this.btnStart87XX.Text.ToLower() == "start")
            {
                this.time87XX.Enabled = true;
                this.btnStart87XX.Text = "Stopped";
                this.lblStatus87XX.Text = "Running";
            }
            else
            {
                this.btnStart87XX.Text = "Start";
                this.time87XX.Enabled = false;
                this.lblStatus87XX.Text = "Stopped";
                this.Cursor = Cursors.Arrow;
            }
        }

        private void btnStart80XX_Click(object sender, EventArgs e)
        {
            if (this.btnStart80XX.Text.ToLower() == "start")
            {
                this.time80XX.Enabled = true;
                this.btnStart80XX.Text = "Stopped";
                this.lblStatus80XX.Text = "Running";
            }
            else
            {
                this.btnStart80XX.Text = "Start";
                this.time80XX.Enabled = false;
                this.lblStatus80XX.Text = "Stopped";
            }
        }

        private void btnStartPartner_Click(object sender, EventArgs e)
        {
            if (this.btnStartPartner.Text.ToLower() == "start")
            {
                this.timePartner.Enabled = true;
                this.btnStartPartner.Text = "Stopped";
                this.lblStatusPartner.Text = "Running";
            }
            else
            {
                this.btnStartPartner.Text = "Start";
                this.timePartner.Enabled = false;
                this.lblStatusPartner.Text = "Stopped";
            }
        }

        private void btnStartAll_Click(object sender, EventArgs e)
        {
            this.time81XX.Enabled = true;
            this.btnStart81XX.Text = "Stop";
            this.lblStatus81XX.Text = "Running";

            this.time82XX.Enabled = true;
            this.btnStart82XX.Text = "Stop";
            this.lblStatus82XX.Text = "Running";

            this.time83XX.Enabled = true;
            this.btnStart83XX.Text = "Stop";
            this.lblStatus83XX.Text = "Running";

            this.time84XX.Enabled = true;
            this.btnStart84XX.Text = "Stop";
            this.lblStatus84XX.Text = "Running";

            this.time85XX.Enabled = true;
            this.btnStart85XX.Text = "Stop";
            this.lblStatus85XX.Text = "Running";

            this.time86XX.Enabled = true;
            this.btnStart86XX.Text = "Stop";
            this.lblStatus86XX.Text = "Running";

            this.time87XX.Enabled = true;
            this.btnStart87XX.Text = "Stop";
            this.lblStatus87XX.Text = "Running";

            this.time80XX.Enabled = true;
            this.btnStart80XX.Text = "Stop";
            this.lblStatus80XX.Text = "Running";

            //this.timePartner.Enabled = true;
            //this.btnStartPartner.Text = "Stop";
            //this.lblStatusPartner.Text = "Running";
        }

        private void btnStopAll_Click(object sender, EventArgs e)
        {
            this.time81XX.Enabled = false;
            this.btnStart81XX.Text = "Start";
            this.lblStatus81XX.Text = "Stopped";

            this.time82XX.Enabled = false;
            this.btnStart82XX.Text = "Start";
            this.lblStatus82XX.Text = "Stopped";

            this.time83XX.Enabled = false;
            this.btnStart83XX.Text = "Start";
            this.lblStatus83XX.Text = "Stopped";

            this.time84XX.Enabled = false;
            this.btnStart84XX.Text = "Start";
            this.lblStatus84XX.Text = "Stopped";

            this.time85XX.Enabled = false;
            this.btnStart85XX.Text = "Start";
            this.lblStatus85XX.Text = "Stopped";

            this.time86XX.Enabled = false;
            this.btnStart86XX.Text = "Start";
            this.lblStatus86XX.Text = "Stopped";

            this.time87XX.Enabled = false;
            this.btnStart87XX.Text = "Start";
            this.lblStatus87XX.Text = "Stopped";

            this.time80XX.Enabled = false;
            this.btnStart80XX.Text = "Start";
            this.lblStatus80XX.Text = "Stopped";

            //this.timePartner.Enabled = false;
            //this.btnStartPartner.Text = "Start";
            //this.lblStatusPartner.Text = "Stopped";
        }

        private void btnReset_Click(object sender, EventArgs e)
        {
            try
            {
                lock (this.total81XX)
                {
                    for (int i = 0; i < this.total81XX.Length; i++)
                    {
                        this.total81XX[i] = 0;
                    }
                }
                this.RefreshCounts82();
            }
            catch { }

            try
            {
                lock (this.total82XX)
                {
                    for (int i = 0; i < this.total82XX.Length; i++)
                    {
                        this.total82XX[i] = 0;
                    }
                }
                this.RefreshCounts82();
            }
            catch { }

            try
            {
                lock (this.total83XX)
                {
                    for (int i = 0; i < this.total83XX.Length; i++)
                    {
                        this.total83XX[i] = 0;
                    }
                }
                this.RefreshCounts83();
            }
            catch { }

            try
            {
                lock (this.total84XX)
                {
                    for (int i = 0; i < this.total84XX.Length; i++)
                    {
                        this.total84XX[i] = 0;
                    }
                }
                this.RefreshCounts84();
            }
            catch { }

            try
            {
                lock (this.total85XX)
                {
                    for (int i = 0; i < this.total85XX.Length; i++)
                    {
                        this.total85XX[i] = 0;
                    }
                }
                this.RefreshCounts85();
            }
            catch { }

            try
            {
                lock (this.total86XX)
                {
                    for (int i = 0; i < this.total86XX.Length; i++)
                    {
                        this.total86XX[i] = 0;
                    }
                }
                this.RefreshCounts86();
            }
            catch { }

            try
            {
                lock (this.total87XX)
                {
                    for (int i = 0; i < this.total87XX.Length; i++)
                    {
                        this.total87XX[i] = 0;
                    }
                }
                this.RefreshCounts87();
            }
            catch { }

            try
            {
                lock (this.total80XX)
                {
                    for (int i = 0; i < this.total80XX.Length; i++)
                    {
                        this.total80XX[i] = 0;
                    }
                }
                this.RefreshCounts80XX();
            }
            catch { }

            //try
            //{
            //    lock (this.totalPartner)
            //    {
            //        for (int i = 0; i < this.totalPartner.Length; i++)
            //        {
            //            this.totalPartner[i] = 0;
            //        }
            //    }
            //    this.RefreshCountsPartner();
            //}
            //catch { }
        }

        #endregion Button Events

        #region Timer Events
        private void time80XX_Tick(object sender, EventArgs e)
        {
            this.time80XX.Enabled = false;
            try
            {
                lock (work87)
                {
                    ArrayList ins = MsgIn_80Manager.SelectAllMsgProcess();
                    if (ins != null)
                    {
                        this.Cursor = Cursors.AppStarting;
                        int count = ins.Count;
                        this.txtTotalSms80XX.Text = Convert.ToString((int)(int.Parse(this.txtTotalSms80XX.Text) + count));

                        foreach (MsgIn_80Info @in in ins)
                        {
                            // Process
                            ProcessMO_80 msgIn = new ProcessMO_80();
                            msgIn.objMsgIn80 = @in;
                            this.work80.Add(msgIn);
                        }
                    }
                }
                this.time80XX.Enabled = true;
            }
            catch (Exception ex)
            {
                string message = ex.Message;
                this.time80XX.Enabled = true;
            }
        }

        private void time81XX_Tick(object sender, EventArgs e)
        {
            this.time81XX.Enabled = false;
            try
            {
                lock (work81)
                {
                    ArrayList ins = MsgIn_81Manager.SelectAllMsgProcess();
                    if (ins != null)
                    {
                        this.Cursor = Cursors.AppStarting;
                        int count = ins.Count;
                        this.txtTotalSms81XX.Text = Convert.ToString((int)(int.Parse(this.txtTotalSms81XX.Text) + count));

                        foreach (MsgIn_81Info @in in ins)
                        {
                            // Process
                            ProcessMO_81 msgIn = new ProcessMO_81();
                            msgIn.objMsgIn81 = @in;
                            this.work81.Add(msgIn);
                        }
                    }
                }
                this.time81XX.Enabled = true;
            }
            catch (Exception ex)
            {
                string message = ex.Message;
                this.time81XX.Enabled = true;
            }
        }

        private void time82XX_Tick(object sender, EventArgs e)
        {
            this.time82XX.Enabled = false;
            try
            {
                lock (work82)
                {
                    ArrayList ins = MsgIn_82Manager.SelectAllMsgProcess();
                    if (ins != null)
                    {
                        this.Cursor = Cursors.AppStarting;
                        int count = ins.Count;
                        this.txtTotalSms82XX.Text = Convert.ToString((int)(int.Parse(this.txtTotalSms82XX.Text) + count));

                        foreach (MsgIn_82Info @in in ins)
                        {
                            // Process
                            ProcessMO_82 msgIn = new ProcessMO_82();
                            msgIn.objMsgIn82 = @in;
                            this.work82.Add(msgIn);
                        }
                    }
                }
                this.time82XX.Enabled = true;
            }
            catch (Exception ex)
            {
                string message = ex.Message;
                this.time82XX.Enabled = true;
            }
        }

        private void time83XX_Tick(object sender, EventArgs e)
        {
            this.time83XX.Enabled = false;
            try
            {
                lock (work83)
                {
                    ArrayList ins = MsgIn_83Manager.SelectAllMsgProcess();
                    if (ins != null)
                    {
                        this.Cursor = Cursors.AppStarting;
                        int count = ins.Count;
                        this.txtTotalSms83XX.Text = Convert.ToString((int)(int.Parse(this.txtTotalSms83XX.Text) + count));

                        foreach (MsgIn_83Info @in in ins)
                        {
                            // Process
                            ProcessMO_83 msgIn = new ProcessMO_83();
                            msgIn.objMsgIn83 = @in;
                            this.work83.Add(msgIn);
                        }
                    }
                }
                this.time83XX.Enabled = true;
            }
            catch (Exception ex)
            {
                string message = ex.Message;
                this.time83XX.Enabled = true;
            }
        }

        private void time84XX_Tick(object sender, EventArgs e)
        {
            this.time84XX.Enabled = false;
            try
            {
                lock (work84)
                {
                    ArrayList ins = MsgIn_84Manager.SelectAllMsgProcess();
                    if (ins != null)
                    {
                        this.Cursor = Cursors.AppStarting;
                        int count = ins.Count;
                        this.txtTotalSms84XX.Text = Convert.ToString((int)(int.Parse(this.txtTotalSms84XX.Text) + count));

                        foreach (MsgIn_84Info @in in ins)
                        {
                            // Process
                            ProcessMO_84 msgIn = new ProcessMO_84();
                            msgIn.objMsgIn84 = @in;
                            this.work84.Add(msgIn);
                        }
                    }
                }
                this.time84XX.Enabled = true;
            }
            catch (Exception ex)
            {
                string message = ex.Message;
                this.time84XX.Enabled = true;
            }
        }

        private void time85XX_Tick(object sender, EventArgs e)
        {
            this.time85XX.Enabled = false;
            try
            {
                lock (work85)
                {
                    ArrayList ins = MsgIn_85Manager.SelectAllMsgProcess();
                    if (ins != null)
                    {
                        this.Cursor = Cursors.AppStarting;
                        int count = ins.Count;
                        this.txtTotalSms85XX.Text = Convert.ToString((int)(int.Parse(this.txtTotalSms85XX.Text) + count));

                        foreach (MsgIn_85Info @in in ins)
                        {
                            // Process
                            ProcessMO_85 msgIn = new ProcessMO_85();
                            msgIn.objMsgIn85 = @in;
                            this.work85.Add(msgIn);
                        }
                    }
                }
                this.time85XX.Enabled = true;
            }
            catch (Exception ex)
            {
                string message = ex.Message;
                this.time85XX.Enabled = true;
            }
        }

        private void time86XX_Tick(object sender, EventArgs e)
        {
            this.time86XX.Enabled = false;
            try
            {
                lock (work86)
                {
                    ArrayList ins = MsgIn_86Manager.SelectAllMsgProcess();
                    if (ins != null)
                    {
                        this.Cursor = Cursors.AppStarting;
                        int count = ins.Count;
                        this.txtTotalSms86XX.Text = Convert.ToString((int)(int.Parse(this.txtTotalSms86XX.Text) + count));

                        foreach (MsgIn_86Info @in in ins)
                        {
                            // Process
                            ProcessMO_86 msgIn = new ProcessMO_86();
                            msgIn.objMsgIn86 = @in;
                            this.work86.Add(msgIn);
                        }
                    }
                }
                this.time86XX.Enabled = true;
            }
            catch (Exception ex)
            {
                string message = ex.Message;
                this.time86XX.Enabled = true;
            }
        }

        private void time87XX_Tick(object sender, EventArgs e)
        {
            this.time87XX.Enabled = false;
            try
            {
                lock (work87)
                {
                    ArrayList ins = MsgIn_87Manager.SelectAllMsgProcess();
                    if (ins != null)
                    {
                        this.Cursor = Cursors.AppStarting;
                        int count = ins.Count;
                        this.txtTotalSms87XX.Text = Convert.ToString((int)(int.Parse(this.txtTotalSms87XX.Text) + count));

                        foreach (MsgIn_87Info @in in ins)
                        {
                            // Process
                            ProcessMO_87 msgIn = new ProcessMO_87();
                            msgIn.objMsgIn87 = @in;
                            this.work87.Add(msgIn);
                        }
                    }
                }
                this.time87XX.Enabled = true;
            }
            catch (Exception ex)
            {
                string message = ex.Message;
                this.time87XX.Enabled = true;
            }
        }

        private void timePartner_Tick(object sender, EventArgs e)
        {

        }

        #endregion Timer Events

        #region Text Leave

        private void txtConcurrent81XX_Leave(object sender, EventArgs e)
        {
            try
            {
                this.work81.ConcurrentLimit = int.Parse(this.txtConcurrent81XX.Text);
            }
            catch { }
        }

        private void txtConcurrent82XX_Leave(object sender, EventArgs e)
        {
            try
            {
                this.work82.ConcurrentLimit = int.Parse(this.txtConcurrent82XX.Text);
            }
            catch { }
        }

        private void txtConcurrent83XX_Leave(object sender, EventArgs e)
        {
            try
            {
                this.work83.ConcurrentLimit = int.Parse(this.txtConcurrent83XX.Text);
            }
            catch { }
        }

        private void txtConcurrent84XX_Leave(object sender, EventArgs e)
        {
            try
            {
                this.work84.ConcurrentLimit = int.Parse(this.txtConcurrent84XX.Text);
            }
            catch { }
        }

        private void txtConcurrent85XX_Leave(object sender, EventArgs e)
        {
            try
            {
                this.work85.ConcurrentLimit = int.Parse(this.txtConcurrent85XX.Text);
            }
            catch { }
        }

        private void txtConcurrent86XX_Leave(object sender, EventArgs e)
        {
            try
            {
                this.work86.ConcurrentLimit = int.Parse(this.txtConcurrent81XX.Text);
            }
            catch { }
        }

        private void txtConcurrent87XX_Leave(object sender, EventArgs e)
        {
            try
            {
                this.work87.ConcurrentLimit = int.Parse(this.txtConcurrent87XX.Text);
            }
            catch { }
        }

        private void txtConcurrent80XX_Leave(object sender, EventArgs e)
        {
            try
            {
                this.work80.ConcurrentLimit = int.Parse(this.txtConcurrent80XX.Text);
            }
            catch { }
        }

        private void txtConcurrentPartner_Leave(object sender, EventArgs e)
        {
            try
            {
                this.workPartner.ConcurrentLimit = int.Parse(this.txtConcurrentPartner.Text);
            }
            catch { }
        }

        private void txtMaxthread81XX_Leave(object sender, EventArgs e)
        {
            try
            {
                ((WorkThreadPool)this.work81.WorkerPool).MaxThreads = int.Parse(this.txtMaxthread81XX.Text);
            }
            catch { }
        }

        private void txtMaxthread82XX_Leave(object sender, EventArgs e)
        {
            try
            {
                ((WorkThreadPool)this.work82.WorkerPool).MaxThreads = int.Parse(this.txtMaxthread82XX.Text);
            }
            catch { }
        }

        private void txtMaxthread83XX_Leave(object sender, EventArgs e)
        {
            try
            {
                ((WorkThreadPool)this.work83.WorkerPool).MaxThreads = int.Parse(this.txtMaxthread83XX.Text);
            }
            catch { }
        }

        private void txtMaxthread84XX_Leave(object sender, EventArgs e)
        {
            try
            {
                ((WorkThreadPool)this.work84.WorkerPool).MaxThreads = int.Parse(this.txtMaxthread84XX.Text);
            }
            catch { }
        }

        private void txtMaxthread85XX_Leave(object sender, EventArgs e)
        {
            try
            {
                ((WorkThreadPool)this.work85.WorkerPool).MaxThreads = int.Parse(this.txtMaxthread85XX.Text);
            }
            catch { }
        }

        private void txtMaxthread86XX_Leave(object sender, EventArgs e)
        {
            try
            {
                ((WorkThreadPool)this.work86.WorkerPool).MaxThreads = int.Parse(this.txtMaxthread86XX.Text);
            }
            catch { }
        }

        private void txtMaxthread87XX_Leave(object sender, EventArgs e)
        {
            try
            {
                ((WorkThreadPool)this.work87.WorkerPool).MaxThreads = int.Parse(this.txtMaxthread87XX.Text);
            }
            catch { }
        }

        private void txtMaxthread80XX_Leave(object sender, EventArgs e)
        {
            try
            {
                ((WorkThreadPool)this.work80.WorkerPool).MaxThreads = int.Parse(this.txtMaxthread80XX.Text);
            }
            catch { }
        }

        private void txtMaxthreadPartner_Leave(object sender, EventArgs e)
        {
            try
            {
                ((WorkThreadPool)this.workPartner.WorkerPool).MaxThreads = int.Parse(this.txtMaxthreadPartner.Text);
            }
            catch { }
        }

#endregion Text Leave

        #region ReCounting
        /// <summary>
        /// Counting 81
        /// </summary>
        private void RefreshCounts81()
        {
            try
            {
                if (this.InvokeRequired)
                {
                    MethodInvoker mi = new MethodInvoker(RefreshCounts81);
                    this.BeginInvoke(mi);
                }
                else
                {
                    lock (this.lblComplete81XX)
                    {
                        this.lblComplete81XX.Text = this.total81XX[5].ToString("N0");
                    }
                    lock (this.lblFail81XX)
                    {
                        this.lblFail81XX.Text = this.total81XX[4].ToString("N0");
                    }
                    lock (this.lblRun81XX)
                    {
                        this.lblRun81XX.Text = this.total81XX[3].ToString("N0");
                    }
                    lock (this.lblQueue81XX)
                    {
                        this.lblQueue81XX.Text = this.total81XX[2].ToString("N0");
                    }
                    lock (this.lblSche81XX)
                    {
                        this.lblSche81XX.Text = this.total81XX[1].ToString("N0");
                    }
                }
            }
            catch { }
        }

        /// <summary>
        /// Counting 82
        /// </summary>
        private void RefreshCounts82()
        {
            try
            {
                if (this.InvokeRequired)
                {
                    MethodInvoker mi = new MethodInvoker(RefreshCounts82);
                    this.BeginInvoke(mi);
                }
                else
                {
                    lock (this.lblComplete82XX)
                    {
                        this.lblComplete82XX.Text = this.total82XX[5].ToString("N0");
                    }
                    lock (this.lblFail82XX)
                    {
                        this.lblFail82XX.Text = this.total82XX[4].ToString("N0");
                    }
                    lock (this.lblRun82XX)
                    {
                        this.lblRun82XX.Text = this.total82XX[3].ToString("N0");
                    }
                    lock (this.lblQueue82XX)
                    {
                        this.lblQueue82XX.Text = this.total82XX[2].ToString("N0");
                    }
                    lock (this.lblSche82XX)
                    {
                        this.lblSche82XX.Text = this.total82XX[1].ToString("N0");
                    }
                }
            }
            catch { }
        }

        /// <summary>
        /// Counting 83
        /// </summary>
        private void RefreshCounts83()
        {
            try
            {
                if (this.InvokeRequired)
                {
                    MethodInvoker mi = new MethodInvoker(RefreshCounts83);
                    this.BeginInvoke(mi);
                }
                else
                {
                    lock (this.lblComplete83XX)
                    {
                        this.lblComplete83XX.Text = this.total83XX[5].ToString("N0");
                    }
                    lock (this.lblFail83XX)
                    {
                        this.lblFail83XX.Text = this.total83XX[4].ToString("N0");
                    }
                    lock (this.lblRun83XX)
                    {
                        this.lblRun83XX.Text = this.total83XX[3].ToString("N0");
                    }
                    lock (this.lblQueue83XX)
                    {
                        this.lblQueue83XX.Text = this.total83XX[2].ToString("N0");
                    }
                    lock (this.lblSche83XX)
                    {
                        this.lblSche83XX.Text = this.total83XX[1].ToString("N0");
                    }
                }
            }
            catch { }
        }

        /// <summary>
        /// Counting 84
        /// </summary>
        private void RefreshCounts84()
        {
            try
            {
                if (this.InvokeRequired)
                {
                    MethodInvoker mi = new MethodInvoker(RefreshCounts84);
                    this.BeginInvoke(mi);
                }
                else
                {
                    lock (this.lblComplete84XX)
                    {
                        this.lblComplete84XX.Text = this.total84XX[5].ToString("N0");
                    }
                    lock (this.lblFail84XX)
                    {
                        this.lblFail84XX.Text = this.total84XX[4].ToString("N0");
                    }
                    lock (this.lblRun84XX)
                    {
                        this.lblRun84XX.Text = this.total84XX[3].ToString("N0");
                    }
                    lock (this.lblQueue84XX)
                    {
                        this.lblQueue84XX.Text = this.total84XX[2].ToString("N0");
                    }
                    lock (this.lblSche84XX)
                    {
                        this.lblSche84XX.Text = this.total84XX[1].ToString("N0");
                    }
                }
            }
            catch { }
        }

        /// <summary>
        /// Counting 85
        /// </summary>
        private void RefreshCounts85()
        {
            try
            {
                if (this.InvokeRequired)
                {
                    MethodInvoker mi = new MethodInvoker(RefreshCounts85);
                    this.BeginInvoke(mi);
                }
                else
                {
                    lock (this.lblComplete85XX)
                    {
                        this.lblComplete85XX.Text = this.total85XX[5].ToString("N0");
                    }
                    lock (this.lblFail85XX)
                    {
                        this.lblFail85XX.Text = this.total85XX[4].ToString("N0");
                    }
                    lock (this.lblRun85XX)
                    {
                        this.lblRun85XX.Text = this.total85XX[3].ToString("N0");
                    }
                    lock (this.lblQueue85XX)
                    {
                        this.lblQueue85XX.Text = this.total85XX[2].ToString("N0");
                    }
                    lock (this.lblSche85XX)
                    {
                        this.lblSche85XX.Text = this.total85XX[1].ToString("N0");
                    }
                }
            }
            catch { }
        }

        /// <summary>
        /// Counting 86
        /// </summary>
        private void RefreshCounts86()
        {
            try
            {
                if (this.InvokeRequired)
                {
                    MethodInvoker mi = new MethodInvoker(RefreshCounts86);
                    this.BeginInvoke(mi);
                }
                else
                {
                    lock (this.lblComplete86XX)
                    {
                        this.lblComplete86XX.Text = this.total86XX[5].ToString("N0");
                    }
                    lock (this.lblFail86XX)
                    {
                        this.lblFail86XX.Text = this.total86XX[4].ToString("N0");
                    }
                    lock (this.lblRun86XX)
                    {
                        this.lblRun86XX.Text = this.total86XX[3].ToString("N0");
                    }
                    lock (this.lblQueue86XX)
                    {
                        this.lblQueue86XX.Text = this.total86XX[2].ToString("N0");
                    }
                    lock (this.lblSche86XX)
                    {
                        this.lblSche86XX.Text = this.total86XX[1].ToString("N0");
                    }
                }
            }
            catch { }
        }

        /// <summary>
        /// Counting 87
        /// </summary>
        private void RefreshCounts87()
        {
            try
            {
                if (this.InvokeRequired)
                {
                    MethodInvoker mi = new MethodInvoker(RefreshCounts87);
                    this.BeginInvoke(mi);
                }
                else
                {
                    lock (this.lblComplete87XX)
                    {
                        this.lblComplete87XX.Text = this.total87XX[5].ToString("N0");
                    }
                    lock (this.lblFail87XX)
                    {
                        this.lblFail87XX.Text = this.total87XX[4].ToString("N0");
                    }
                    lock (this.lblRun87XX)
                    {
                        this.lblRun87XX.Text = this.total87XX[3].ToString("N0");
                    }
                    lock (this.lblQueue87XX)
                    {
                        this.lblQueue87XX.Text = this.total87XX[2].ToString("N0");
                    }
                    lock (this.lblSche87XX)
                    {
                        this.lblSche87XX.Text = this.total87XX[1].ToString("N0");
                    }
                }
            }
            catch { }
        }

        /// <summary>
        /// Counting 87
        /// </summary>
        private void RefreshCounts80XX()
        {
            try
            {
                if (this.InvokeRequired)
                {
                    MethodInvoker mi = new MethodInvoker(RefreshCounts80XX);
                    this.BeginInvoke(mi);
                }
                else
                {
                    lock (this.lblComplete80XX)
                    {
                        this.lblComplete80XX.Text = this.total80XX[5].ToString("N0");
                    }
                    lock (this.lblFail80XX)
                    {
                        this.lblFail80XX.Text = this.total80XX[4].ToString("N0");
                    }
                    lock (this.lblRun80XX)
                    {
                        this.lblRun80XX.Text = this.total80XX[3].ToString("N0");
                    }
                    lock (this.lblQueue80XX)
                    {
                        this.lblQueue80XX.Text = this.total80XX[2].ToString("N0");
                    }
                    lock (this.lblSche87XX)
                    {
                        this.lblSche80XX.Text = this.total80XX[1].ToString("N0");
                    }
                }
            }
            catch { }
        }

        /// <summary>
        /// Counting Partner
        /// </summary>
        private void RefreshCountsPartner()
        {
            try
            {
                if (this.InvokeRequired)
                {
                    MethodInvoker mi = new MethodInvoker(RefreshCountsPartner);
                    this.BeginInvoke(mi);
                }
                else
                {
                    lock (this.lblCompletePartner)
                    {
                        this.lblCompletePartner.Text = this.totalPartner[5].ToString("N0");
                    }
                    lock (this.lblFailPartner)
                    {
                        this.lblFailPartner.Text = this.totalPartner[4].ToString("N0");
                    }
                    lock (this.lblRunPartner)
                    {
                        this.lblRunPartner.Text = this.totalPartner[3].ToString("N0");
                    }
                    lock (this.lblQueuePartner)
                    {
                        this.lblQueuePartner.Text = this.totalPartner[2].ToString("N0");
                    }
                    lock (this.lblSchePartner)
                    {
                        this.lblSchePartner.Text = this.totalPartner[1].ToString("N0");
                    }
                }
            }
            catch { }
        }

        #endregion ReCounting

        #region Work 80
        /// <summary>
        ///   All work is completed. Update the GUI.
        /// </summary>
        private void work80_AllWorkCompleted(object sender, EventArgs e)
        {
            if (this.InvokeRequired)
            {
                this.Invoke(new EventHandler(work80_AllWorkCompleted), new object[] { sender, e });
            }
            else
            {
                lock (this.total80XX)
                {
                    total80XX = new int[6];
                }
                RefreshCounts80XX();
            }
        }

        /// <summary>
        ///   Record where the state of the work item.
        /// </summary>
        private void work80_ChangedWorkItemState(object sender, ChangedWorkItemStateEventArgs e)
        {
            lock (total80XX)
            {
                if (e.PreviousState != WorkItemState.Failing)
                {
                    IntPtr ptr1;
                    this.total80XX[(int)(ptr1 = (IntPtr)e.PreviousState)] = this.total80XX[(int)ptr1] - 1;
                }
                if (e.PreviousState != WorkItemState.Failing)
                {
                    IntPtr ptr2;
                    this.total80XX[(int)(ptr2 = (IntPtr)e.WorkItem.State)] = this.total80XX[(int)ptr2] + 1;
                }
            }

            if (DateTime.Now > this.nextRefreshTime)
            {
                RefreshCounts80XX();
                this.nextRefreshTime = DateTime.Now + this.refreshInterval;
            }
        }

        /// <summary>
        /// Work exception
        /// </summary>
        private void work80_WorkerException(object sender, ResourceExceptionEventArgs e)
        {
            Application.OnThreadException(e.Exception);
        }

        /// <summary>
        /// Work fail
        /// </summary>
        private void work80_FailedWorkItem(object sender, WorkItemEventArgs e)
        {
            Application.OnThreadException(e.WorkItem.FailedException);
        }

        #endregion Work 80

        #region Work 81
        /// <summary>
        ///   All work is completed. Update the GUI.
        /// </summary>
        private void work81_AllWorkCompleted(object sender, EventArgs e)
        {
            if (this.InvokeRequired)
            {
                this.Invoke(new EventHandler(work81_AllWorkCompleted), new object[] { sender, e });
            }
            else
            {
                lock (this.total81XX)
                {
                    total81XX = new int[6];
                }
                RefreshCounts81();
                Cursor = Cursors.Arrow;
            }
        }

        /// <summary>
        ///   Record where the state of the work item.
        /// </summary>
        private void work81_ChangedWorkItemState(object sender, ChangedWorkItemStateEventArgs e)
        {
            lock (total81XX)
            {
                if (e.PreviousState != WorkItemState.Failing)
                {
                    IntPtr ptr1;
                    this.total81XX[(int)(ptr1 = (IntPtr)e.PreviousState)] = this.total81XX[(int)ptr1] - 1;
                }
                if (e.PreviousState != WorkItemState.Failing)
                {
                    IntPtr ptr2;
                    this.total81XX[(int)(ptr2 = (IntPtr)e.WorkItem.State)] = this.total81XX[(int)ptr2] + 1;
                }
            }

            if (DateTime.Now > this.nextRefreshTime)
            {
                RefreshCounts81();
                this.nextRefreshTime = DateTime.Now + this.refreshInterval;
            }
        }

        /// <summary>
        /// Work exception
        /// </summary>
        private void work81_WorkerException(object sender, ResourceExceptionEventArgs e)
        {
            Application.OnThreadException(e.Exception);
        }

        /// <summary>
        /// Work fail
        /// </summary>
        private void work81_FailedWorkItem(object sender, WorkItemEventArgs e)
        {
            Application.OnThreadException(e.WorkItem.FailedException);
        }

        #endregion Work 81

        #region Work 82

        /// <summary>
        ///   All work is completed. Update the GUI.
        /// </summary>
        private void work82_AllWorkCompleted(object sender, EventArgs e)
        {
            if (this.InvokeRequired)
            {
                this.Invoke(new EventHandler(work82_AllWorkCompleted), new object[] { sender, e });
            }
            else
            {
                lock (this.total82XX)
                {
                    total82XX = new int[6];
                }
                RefreshCounts82();
            }
        }

        /// <summary>
        ///   Record where the state of the work item.
        /// </summary>
        private void work82_ChangedWorkItemState(object sender, ChangedWorkItemStateEventArgs e)
        {
            lock (total82XX)
            {
                if (e.PreviousState != WorkItemState.Failing)
                {
                    IntPtr ptr1;
                    this.total82XX[(int)(ptr1 = (IntPtr)e.PreviousState)] = this.total82XX[(int)ptr1] - 1;
                }
                if (e.PreviousState != WorkItemState.Failing)
                {
                    IntPtr ptr2;
                    this.total82XX[(int)(ptr2 = (IntPtr)e.WorkItem.State)] = this.total82XX[(int)ptr2] + 1;
                }
            }

            if (DateTime.Now > this.nextRefreshTime)
            {
                RefreshCounts82();
                this.nextRefreshTime = DateTime.Now + this.refreshInterval;
            }
        }

        /// <summary>
        /// Work exception
        /// </summary>
        private void work82_WorkerException(object sender, ResourceExceptionEventArgs e)
        {
            Application.OnThreadException(e.Exception);
        }

        /// <summary>
        /// Work fail
        /// </summary>
        private void work82_FailedWorkItem(object sender, WorkItemEventArgs e)
        {
            Application.OnThreadException(e.WorkItem.FailedException);
        }
        #endregion Work 82

        #region Work 83
        /// <summary>
        ///   All work is completed. Update the GUI.
        /// </summary>
        private void work83_AllWorkCompleted(object sender, EventArgs e)
        {
            if (this.InvokeRequired)
            {
                this.Invoke(new EventHandler(work83_AllWorkCompleted), new object[] { sender, e });
            }
            else
            {
                lock (this.total83XX)
                {
                    total83XX = new int[6];
                }
                RefreshCounts83();
            }
        }

        /// <summary>
        ///   Record where the state of the work item.
        /// </summary>
        private void work83_ChangedWorkItemState(object sender, ChangedWorkItemStateEventArgs e)
        {
            lock (total83XX)
            {
                if (e.PreviousState != WorkItemState.Failing)
                {
                    IntPtr ptr1;
                    this.total83XX[(int)(ptr1 = (IntPtr)e.PreviousState)] = this.total83XX[(int)ptr1] - 1;
                }
                if (e.PreviousState != WorkItemState.Failing)
                {
                    IntPtr ptr2;
                    this.total83XX[(int)(ptr2 = (IntPtr)e.WorkItem.State)] = this.total83XX[(int)ptr2] + 1;
                }
            }

            if (DateTime.Now > this.nextRefreshTime)
            {
                RefreshCounts83();
                this.nextRefreshTime = DateTime.Now + this.refreshInterval;
            }
        }

        /// <summary>
        /// Work exception
        /// </summary>
        private void work83_WorkerException(object sender, ResourceExceptionEventArgs e)
        {
            Application.OnThreadException(e.Exception);
        }

        /// <summary>
        /// Work fail
        /// </summary>
        private void work83_FailedWorkItem(object sender, WorkItemEventArgs e)
        {
            Application.OnThreadException(e.WorkItem.FailedException);
        }

        #endregion Work 83

        #region Work 84
        /// <summary>
        ///   All work is completed. Update the GUI.
        /// </summary>
        private void work84_AllWorkCompleted(object sender, EventArgs e)
        {
            if (this.InvokeRequired)
            {
                this.Invoke(new EventHandler(work84_AllWorkCompleted), new object[] { sender, e });
            }
            else
            {
                lock (this.total84XX)
                {
                    total84XX = new int[6];
                }
                RefreshCounts84();
            }
        }

        /// <summary>
        ///   Record where the state of the work item.
        /// </summary>
        private void work84_ChangedWorkItemState(object sender, ChangedWorkItemStateEventArgs e)
        {
            lock (total84XX)
            {
                if (e.PreviousState != WorkItemState.Failing)
                {
                    IntPtr ptr1;
                    this.total84XX[(int)(ptr1 = (IntPtr)e.PreviousState)] = this.total84XX[(int)ptr1] - 1;
                }
                if (e.PreviousState != WorkItemState.Failing)
                {
                    IntPtr ptr2;
                    this.total84XX[(int)(ptr2 = (IntPtr)e.WorkItem.State)] = this.total84XX[(int)ptr2] + 1;
                }
            }

            if (DateTime.Now > this.nextRefreshTime)
            {
                RefreshCounts84();
                this.nextRefreshTime = DateTime.Now + this.refreshInterval;
            }
        }

        /// <summary>
        /// Work exception
        /// </summary>
        private void work84_WorkerException(object sender, ResourceExceptionEventArgs e)
        {
            Application.OnThreadException(e.Exception);
        }

        /// <summary>
        /// Work fail
        /// </summary>
        private void work84_FailedWorkItem(object sender, WorkItemEventArgs e)
        {
            Application.OnThreadException(e.WorkItem.FailedException);
        }

        #endregion Work 84

        #region Work 85
        /// <summary>
        ///   All work is completed. Update the GUI.
        /// </summary>
        private void work85_AllWorkCompleted(object sender, EventArgs e)
        {
            if (this.InvokeRequired)
            {
                this.Invoke(new EventHandler(work85_AllWorkCompleted), new object[] { sender, e });
            }
            else
            {
                lock (this.total85XX)
                {
                    total85XX = new int[6];
                }
                RefreshCounts85();
            }
        }

        /// <summary>
        ///   Record where the state of the work item.
        /// </summary>
        private void work85_ChangedWorkItemState(object sender, ChangedWorkItemStateEventArgs e)
        {
            lock (total85XX)
            {
                if (e.PreviousState != WorkItemState.Failing)
                {
                    IntPtr ptr1;
                    this.total85XX[(int)(ptr1 = (IntPtr)e.PreviousState)] = this.total85XX[(int)ptr1] - 1;
                }
                if (e.PreviousState != WorkItemState.Failing)
                {
                    IntPtr ptr2;
                    this.total85XX[(int)(ptr2 = (IntPtr)e.WorkItem.State)] = this.total85XX[(int)ptr2] + 1;
                }
            }

            if (DateTime.Now > this.nextRefreshTime)
            {
                RefreshCounts85();
                this.nextRefreshTime = DateTime.Now + this.refreshInterval;
            }
        }

        /// <summary>
        /// Work exception
        /// </summary>
        private void work85_WorkerException(object sender, ResourceExceptionEventArgs e)
        {
            Application.OnThreadException(e.Exception);
        }

        /// <summary>
        /// Work fail
        /// </summary>
        private void work85_FailedWorkItem(object sender, WorkItemEventArgs e)
        {
            Application.OnThreadException(e.WorkItem.FailedException);
        }

        #endregion Work 85

        #region Work 86
        /// <summary>
        ///   All work is completed. Update the GUI.
        /// </summary>
        private void work86_AllWorkCompleted(object sender, EventArgs e)
        {
            if (this.InvokeRequired)
            {
                this.Invoke(new EventHandler(work86_AllWorkCompleted), new object[] { sender, e });
            }
            else
            {
                lock (this.total86XX)
                {
                    total86XX = new int[6];
                }
                RefreshCounts86();
            }
        }

        /// <summary>
        ///   Record where the state of the work item.
        /// </summary>
        private void work86_ChangedWorkItemState(object sender, ChangedWorkItemStateEventArgs e)
        {
            lock (total86XX)
            {
                if (e.PreviousState != WorkItemState.Failing)
                {
                    IntPtr ptr1;
                    this.total86XX[(int)(ptr1 = (IntPtr)e.PreviousState)] = this.total86XX[(int)ptr1] - 1;
                }
                if (e.PreviousState != WorkItemState.Failing)
                {
                    IntPtr ptr2;
                    this.total86XX[(int)(ptr2 = (IntPtr)e.WorkItem.State)] = this.total86XX[(int)ptr2] + 1;
                }
            }

            if (DateTime.Now > this.nextRefreshTime)
            {
                RefreshCounts86();
                this.nextRefreshTime = DateTime.Now + this.refreshInterval;
            }
        }

        /// <summary>
        /// Work exception
        /// </summary>
        private void work86_WorkerException(object sender, ResourceExceptionEventArgs e)
        {
            Application.OnThreadException(e.Exception);
        }

        /// <summary>
        /// Work fail
        /// </summary>
        private void work86_FailedWorkItem(object sender, WorkItemEventArgs e)
        {
            Application.OnThreadException(e.WorkItem.FailedException);
        }
        #endregion Work 86

        #region Work 87
        /// <summary>
        ///   All work is completed. Update the GUI.
        /// </summary>
        private void work87_AllWorkCompleted(object sender, EventArgs e)
        {
            if (this.InvokeRequired)
            {
                this.Invoke(new EventHandler(work87_AllWorkCompleted), new object[] { sender, e });
            }
            else
            {
                lock (this.total87XX)
                {
                    total87XX = new int[6];
                }
                RefreshCounts87();
            }
        }

        /// <summary>
        ///   Record where the state of the work item.
        /// </summary>
        private void work87_ChangedWorkItemState(object sender, ChangedWorkItemStateEventArgs e)
        {
            lock (total87XX)
            {
                if (e.PreviousState != WorkItemState.Failing)
                {
                    IntPtr ptr1;
                    this.total87XX[(int)(ptr1 = (IntPtr)e.PreviousState)] = this.total87XX[(int)ptr1] - 1;
                }
                if (e.PreviousState != WorkItemState.Failing)
                {
                    IntPtr ptr2;
                    this.total87XX[(int)(ptr2 = (IntPtr)e.WorkItem.State)] = this.total87XX[(int)ptr2] + 1;
                }
            }

            if (DateTime.Now > this.nextRefreshTime)
            {
                RefreshCounts87();
                this.nextRefreshTime = DateTime.Now + this.refreshInterval;
            }
        }

        /// <summary>
        /// Work exception
        /// </summary>
        private void work87_WorkerException(object sender, ResourceExceptionEventArgs e)
        {
            Application.OnThreadException(e.Exception);
        }

        /// <summary>
        /// Work fail
        /// </summary>
        private void work87_FailedWorkItem(object sender, WorkItemEventArgs e)
        {
            Application.OnThreadException(e.WorkItem.FailedException);
        }

        #endregion Work 87

        #region Work Partner
        /// <summary>
        ///   All work is completed. Update the GUI.
        /// </summary>
        private void workPartner_AllWorkCompleted(object sender, EventArgs e)
        {
            if (this.InvokeRequired)
            {
                this.Invoke(new EventHandler(workPartner_AllWorkCompleted), new object[] { sender, e });
            }
            else
            {
                lock (this.totalPartner)
                {
                    totalPartner = new int[6];
                }
                RefreshCountsPartner();
            }
        }

        /// <summary>
        ///   Record where the state of the work item.
        /// </summary>
        private void workPartner_ChangedWorkItemState(object sender, ChangedWorkItemStateEventArgs e)
        {
            lock (totalPartner)
            {
                if (e.PreviousState != WorkItemState.Failing)
                {
                    IntPtr ptr1;
                    this.totalPartner[(int)(ptr1 = (IntPtr)e.PreviousState)] = this.totalPartner[(int)ptr1] - 1;
                }
                if (e.PreviousState != WorkItemState.Failing)
                {
                    IntPtr ptr2;
                    this.totalPartner[(int)(ptr2 = (IntPtr)e.WorkItem.State)] = this.totalPartner[(int)ptr2] + 1;
                }
            }

            if (DateTime.Now > this.nextRefreshTime)
            {
                RefreshCountsPartner();
                this.nextRefreshTime = DateTime.Now + this.refreshInterval;
            }
        }

        /// <summary>
        /// Work exception
        /// </summary>
        private void workPartner_WorkerException(object sender, ResourceExceptionEventArgs e)
        {
            Application.OnThreadException(e.Exception);
        }

        /// <summary>
        /// Work fail
        /// </summary>
        private void workPartner_FailedWorkItem(object sender, WorkItemEventArgs e)
        {
            Application.OnThreadException(e.WorkItem.FailedException);
        }

        #endregion Work Partner
    }
}